#include <event2/event.h>
#include <signal.h>

void sigint_cb(int sock, short which, void *arg)
{
    printf("signal event\r\n");
}

void sigkill_cb(int sock, short which, void *arg)
{
    printf("kill event\r\n");
    event *ev = (event*) arg;

    if(!evsignal_pending(ev, NULL)){
        event_del(ev);
        event_add(ev,NULL);
    }
}

int main() {
    event_base *base = event_base_new();
    /* add signal */
    event *csig = evsignal_new(base,SIGINT, sigint_cb, base);
    if(!csig){
        perror("create signal event failed\r\n");
        return -1;
    }
    if(evsignal_add(csig, 0) != 0){
        perror("add signal event failed\r\n");
        return -1;
    }

    /* add kill signal */
    event *ksig = event_new(base, SIGTERM, EV_SIGNAL, sigkill_cb, event_self_cbarg());

    if(evsignal_add(ksig, 0) != 0){
        perror("add signal event failed\r\n");
        return -1;
    }
    event_base_dispatch(base);

    event_free(csig);
    event_base_free(base);

    return 1;

}